//
//  NSDictionary+YWK.m
//  YWKUser
//
//  Copyright © 2016年 iCareTech. All rights reserved.
//

#import "NSDictionary+YWK.h"

#define OmitNullMethod @selector(valueOmittingNullValues)
#define OmitNullRecursively(x) ([x respondsToSelector:OmitNullMethod] ? [x performSelector:OmitNullMethod] : x)

@implementation NSDictionary(YWK)
- (NSDictionary *)valueOmittingNullValues
{
    NSMutableDictionary *newDict = [NSMutableDictionary dictionaryWithCapacity:[self count]];
    for (id key in [self allKeys])
    {
        id obj = [self objectForKey:key];
        if (obj != [NSNull null])
        {
            [newDict setObject:OmitNullRecursively(obj)
                        forKey:key];
        }
        else
        {
            [newDict setObject:@""
                        forKey:key];
        }
    }
    return newDict;
}

@end
